<%@ page import="com.hz.web.entity.UserEntity" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    response.setHeader("X-Frame-Options", "SAMEORIGIN");
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String userId = new String(request.getParameter("userId").getBytes("ISO-8859-1"), "utf-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <jsp:include page="../../public/public.jsp"/>
<body>

<div id="certificatory" title="企业授证"  style="width:300px;height:370px;padding:10px;">
    <form id="certificatoryForm" method="post">
        <table align="center" style="margin-top:20px">
            <tr style="height: 30px">
                <td>证书类别:</td>
                <td><input name="certificateType" id="certificateTypeAdd" class="easyui-textbox"
                           data-options="width:150,required:true"/></td>
                <input name="companyId" id="companyId" type="hidden" />
                <td>单位名称:</td>
                <td><input name="companyName" id="companyNameAdd" class="easyui-textbox" data-options="width:150,required:true"/></td>
            </tr>
            <tr style="height: 30px">
                <td>等级:</td>
                <td><input name="certificatelevel" id="certificatelevelAdd" class="easyui-textbox"
                           data-options="width:150,required:true"/></td>
                <td>证书编号:</td>
                <td><input name="certificateNum" id="certificateNumAdd" class="easyui-textbox" data-options="width:150,required:true"/>
                </td>
            </tr>
             <tr style="height: 30px">
                 <td>证书有效期:</td>
                 <td><input name="certificateValidity" id="certificateValidityAdd" class="easyui-datetimebox" data-options="width:150,required:true"/>
                 </td>
             </tr>
        </table>
    </form>
    <input type="button" value="提交信息" onclick="certificatoryCampany();" style="margin-left: 350px; margin-top: 30px; margin-bottom: 20px"/>
</div>
<script>
    /*授予证书*/
    function certificatoryCampany() {
        $.ajax({
            url: '<%=basePath %>companyBase/insertBaseInfo',
            type: 'post',
            data: $("#addForm").serialize(),
            dataType: 'json',
            error: function () {
                $.messager.alert("友情提示", "系统异常,请稍后尝试", "error");
            },
            success: function (data) {
                var row = data.row;
                var msg = data.msg;
                var companyBaseId = data.companyBaseId;
                $("#companyBaseId").val(companyBaseId);
                $("#companyId").val(companyBaseId);
                $.messager.alert("友情提示", msg, "info");

            }
        });




        var row = $('#dg').datagrid('getSelected');
        if (row == null || row == "") {
            $.messager.alert("友情提示", "请先选中一行数据", "error");
            return;
        }
        $('#certificatoryForm').form('reset');
        $("#companyId").html(row.id);
        $('#certificatory').show();
        $('#certificatory').dialog({
            title: '颁证',
            width: 650,
            height: 450,
            closed: false,
            cache: false,
            modal: true,
            buttons: [{
                text: '保存',
                iconCls: 'icon-ok',
                handler: function () {

                    if($("#certificatoryForm").form('validate')) {
                        /* var certificateNum = $("#certificateNumAdd").val().replace(/\s/g, "")
                         if (certificateNumAdd == "") {
                         $.messager.alert("友情提示", "证书编号不允许为空", "error");
                         return;
                         }*/
                        $.ajax({
                            url: '<%=basePath %>companyMange/addCertificatoryCampany',
                            type: 'post',
                            data:$("#certificatoryForm").serialize(),
                            dataType: 'json',
                            error: function () {
                                $.messager.alert("友情提示", "系统异常,请稍后尝试", "error");
                            },
                            success: function (data) {
                                var row = data.row;
                                var msg = data.msg;

                                if (row >= 0) {
                                    $.messager.alert("友情提示", "[授证成功!]", "info");
                                    $('#role').dialog('close');
                                    $('#dg').datagrid("reload");
                                } else {
                                    $.messager.alert("友情提示", "[授证失败!]", "info");
                                }
                                if (msg != null && msg != 'undefined') {
                                    $.messager.alert("友情提示", msg, "info");
                                    return;
                                }
                            }
                        });
                    }


                    else {
                        alert("form 无效")

                    }
                }
            }, {
                text: '退出',
                iconCls: 'icon-no',
                handler: function () {
                    $('#role').dialog('close');
                }
            }]
        });
    }

</script>
</body>
</html>